package com.mcx.modules.proto;

import com.mcx.modules.common.IProto;
import com.mcx.modules.common.MMO_DataStream;

import java.io.*;
import java.util.*;

/**
 * 客户端发送角色已经进入世界地图场景消息
 */
public class WorldMap_RoleAlreadyEnterProto implements IProto
{
    private static MMO_DataStream dataStream = new MMO_DataStream();

    @Override
    public short getProtoCode() { return 13004; }

    public Integer TargetWorldMapSceneId; //目标场景编号
    public Float RolePosX; //角色坐标X
    public Float RolePosY; //角色坐标Y
    public Float RolePosZ; //角色坐标Z
    public Float RoleYAngle; //角色Y轴旋转

    public byte[] ToArray() {
        ByteArrayOutputStream out = new ByteArrayOutputStream();
        try (DataOutputStream outputStream = new DataOutputStream(out)) {
            dataStream.outputStream = outputStream;
            dataStream.WriteShort(getProtoCode());
            dataStream.WriteInt(TargetWorldMapSceneId);
            dataStream.WriteFloat(RolePosX);
            dataStream.WriteFloat(RolePosY);
            dataStream.WriteFloat(RolePosZ);
            dataStream.WriteFloat(RoleYAngle);
        } catch (IOException e) {
            e.printStackTrace();
        }
        return out.toByteArray();    }
    public static WorldMap_RoleAlreadyEnterProto GetProto(byte[] buffer) {
        WorldMap_RoleAlreadyEnterProto proto = new WorldMap_RoleAlreadyEnterProto();
        try (DataInputStream inputStream = new DataInputStream(new ByteArrayInputStream(buffer))) {
            dataStream.inputStream = inputStream;
            proto.TargetWorldMapSceneId = dataStream.ReadInt();
            proto.RolePosX = dataStream.ReadFloat();
            proto.RolePosY = dataStream.ReadFloat();
            proto.RolePosZ = dataStream.ReadFloat();
            proto.RoleYAngle = dataStream.ReadFloat();
        } catch (IOException e) {
            e.printStackTrace();
        }
        return proto;
    }
}